package com.example.distillapplication.data.viewmodel;

import androidx.lifecycle.ViewModel;

import com.example.distillapplication.data.entity.OperationLog;
import com.example.distillapplication.data.entity.UserInfo;
import com.example.distillapplication.data.viewmodel.base.UnPeekLiveData;

/**
 * 存放APP状态相关的viewmodel
 */
public class SharedViewModel extends ViewModel {
    //本次登录人的userinfo
    public final UnPeekLiveData<UserInfo> userinfo = new UnPeekLiveData<>();

    //本次登录日志
    public final UnPeekLiveData<OperationLog> operationLog = new UnPeekLiveData<>();

    public synchronized void setLogoutTime(String logoutTime){
        OperationLog tempOperationLog = operationLog.getValue();
        tempOperationLog.setLogoutTime(logoutTime);
    }

    public synchronized void setOperationData(String data){
        OperationLog tempOperationLog = operationLog.getValue();
        String tempOperationData = tempOperationLog.getOperationData();
        tempOperationData += data;
        tempOperationLog.setOperationData(tempOperationData);
        operationLog.postValue(tempOperationLog);
    }
}
